/*#include <wiringPi.h>
#define pwm_pin 1 //定义PWM引脚 GPIO.1
int main(void) {
  wiringPiSetup();              // wiringPi库初始化
  pinMode(pwm_pin, PWM_OUTPUT); // 设置GPIO.1为PWM输出
  int val = 0;
  while (1) {
    val++;
    if (val >= 1024) {
      val = 0;
    }
    pwmWrite(pwm_pin, val); // 输出占空比为val/1024的pwm波
    delay(10);              // 延时3毫秒
  }
  return 0;
}
*/

#include<stdio.h>
#include<wiringPi.h>
#include<stdlib.h>


const int PWMpin = 1;   //只有wiringPi编号下的1脚（BCM标号下的18脚）支持
void setup();

int main()
{

    setup();
    int val = 0;
    int step = 5;
    while(1)
    {
        if(val>1024)
        {
            step = -step;    
            val = 1024;
        }
        else if(val<0)
        {
            step = -step;
            val = 0;
        }

        pwmWrite(PWMpin,val);
        val+=step;
        delay(10);
    }

    return 0;
}

void setup()
{
    if(-1==wiringPiSetup())
    {
        printf("setup error\n");
        exit(-1);
    }
    pinMode(PWMpin,PWM_OUTPUT);
}
